/*
 * configuration.c
 *
 *  Project Name: ratbox-monitor
 *    Created on: Nov 28, 2010
 *        Author: Daniel J Reidy <dubkat@ratbox.org>
 *            Id: $Id: config.c 21 2012-03-26 03:59:17Z dubkat $
 */


#include <stdio.h>
#include "libconfig.h"
#include "ratbox_lib.h"
#include "setup.h"
#include "settings.h"
#include "logger.h"

int read_config(config_t *);

int
read_config(config_t * conf)
{
	FILE *fd;

	fd = fopen(MONITOR_CONF, "r");
	if(fd == NULL)
	{
		/* we cant log to the logger, because if we can't read the config
		 * we don't know where the log file IS!
		 */
		fprintf(stderr, "Error! Cannot read config file!\n");
		fprintf(stderr,
			"Did you remember to copy %s/etc/monitor.conf.example to %s and edit it??\n",
			MONITOR_PREFIX, MONITOR_CONF);
		exit(EXIT_FAILURE);
	}

	config_init(conf);
	if(config_read(conf, fd) == CONFIG_FALSE)
	{

		fprintf(stderr, "error reading config: %s on line %i",
			config_error_text(conf), config_error_line(conf));

		exit(EXIT_FAILURE);
	}
	fclose(fd);

	return 1;

}
